{% extends 'base.html' %}

{% block header %}
  <h1>{% block title %}Posts{% endblock %}</h1>
  {% if user %}
    <a class="action" href="/blog/create">New</a>
  {% endif %}
{% endblock %}

{% block content %}
  {% for post in posts %}
    <article class="post">
      <header>
        <div>
          <h1>{{ post.title }}</h1>
          <div class="about">by {{ post.username }} on {{ post.created }}</div>
        </div>
        {% if user.id == post.author_id %}
          <a class="action" href="{{ '/blog/update/' + post.id }}">Edit</a>
        {% endif %}
      </header>
      <p class="body">{{ post['body'] }}</p>
    </article>
    {% if not loop.last %}
      <hr>
    {% endif %}
  {% endfor %}
{% endblock %}
